﻿<?php
$__tpl['header'] = '';
$__tpl['footer'] = '';

$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
$catid = empty($_GET['catid']) ? 0 : intval($_GET['catid']);
$categorys = cache_read('goods_categorys.php');
$category_info = $categorys['category_list'][$catid];
if(empty($category_info['attr'])){
	exit('');
}
	$prototypes = Prototype::get_prototypes();
	if($id > 0){
		$oGoods = new Goods();
		$attrs = $oGoods->get_attrs($id);
	}
	$vars['attrs'] = array();
	foreach($category_info['attr'] as $prototypeid => $attr_info){
		$prototype_info = $prototypes[$prototypeid];
		$attr_info['name'] = $prototype_info['name'];
		if(!empty($attr_info['regexp']) && empty($attr_info['prompt']))$attr_info['prompt'] = '...';
		if(is_array($prototype_info['value'])){
			
			// if($id > 0 && isset($attrs) && isset($attrs[$prototypeid])){
			// 	$checked = array_keys($attrs[$prototypeid]['value']);
			// }else{
			// 	$checked = array();
			// }
			// $attr_info['input'] = make_checkbox_group("attrs[{$prototypeid}]", $prototype_info['value'], $checked);

			$inputs = array();
			foreach($prototype_info['value'] as $key => $value){
				if($id > 0 && isset($attrs)){
					$checked = '';
					if(isset($attrs[$prototypeid])){
						if(isset($attrs[$prototypeid]['value'][$key])){
							$checked = ' checked';
						}
					}
				}else{
					$checked = ' checked';	// 默认，分类指定的规格都使用
				}
				$inputs[] = '<label><input type="checkbox" name="attrs['.$prototypeid.'][]" value="'.$key.'"'.$checked.' class="chbox" />'.$value.'</label>';
			}
			$attr_info['inputs'] = $inputs;


		}else{
			if($id > 0 && isset($attrs)){
				if(isset($attrs[$prototypeid])){
					$value = $attrs[$prototypeid]['value'];
				}else{
					$value = '';
				}
			}else{
				$value = trim($attr_info['default']);
			}
			$attr_info['inputs'] = array('<input type="text" name="attrs['.$prototypeid.']" id="attr_'.$prototypeid.'" value="'.$value.'" class="input" style="width:160px;" />');
		}
		$vars['attrs'][] = $attr_info;
	}
	

?>